package com.yej.aiPolice.presenter

import android.os.Looper
import android.util.Log
import com.baidu.ai.aip.bean.FaceSearchBean
import com.baidu.ai.aip.faceAPI.FaceServiceImpl
import com.yej.aiPolice.ui.fragment.SearchFragment

class SearchFragmentPresenter(val searchFragment: SearchFragment) {

    private var faceService = FaceServiceImpl()
    fun searchFace( albumPath: String){
//        var bitMap = IOUtil.readBitmapFromFileDescriptor(albumPath, 200, 200)
//        ivShow?.setImageBitmap(bitMap)
        var postThread = Thread(Runnable {
            //                               var result:FaceAddBean =
//                                faceDatabaseService.add(albumPath, "testALL","ttt","ttt") as FaceAddBean
//
            var result = faceService.faceSearch(albumPath) as FaceSearchBean
            Looper.prepare();
            if(result == null) {
                searchFragment.toast("代码有误")
//                context?.toast("代码错误")
                Log.e("order","代码有误")
            }else{
                if(result.result == null){
                    searchFragment.toast("照片中不存在人脸")
//                    context?.toast("照片中不存在人脸")
                }else{
                    var score =  result.result.user_list[0].score
//                                人脸搜索阈值
                    if(score>80){
                        searchFragment.toast("人脸搜索${result.error_msg} 匹配度${score}")
//                        context?.toast()
                        Log.e("order","算法调用${result.error_msg}")
                        Log.e("order","人脸信息${result.result.user_list[0].user_info}")
                    }else{
                        searchFragment.toast("人脸搜索${result.error_msg} 匹配度${score}")
                    }
                }

            }
            Log.e("order","调用完成")
            Looper.loop();
        })
        postThread.start()
    }
}